package be.florent.brol.client.mvp.impl;

import be.florent.brol.client.mvp.MyView;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Label;

public class MyViewImpl extends Composite implements MyView {

	private Presenter presenter;
	
	private static MyViewImplUiBinder uiBinder = GWT.create(MyViewImplUiBinder.class);

	interface MyViewImplUiBinder extends UiBinder<HTMLPanel, MyViewImpl> {
	}

	@UiField
	Label greeting;
	
	@UiField
	HasValue<String> name; 
	
	@UiField
	Button sendButton;

	public MyViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}

	@Override
	public String getName() {
		return name.getValue();
	}

	@Override
	public void setGreetingMessage(String greetingMessage) {
		greeting.setText(greetingMessage);
	}
	
	@UiHandler("sendButton")
	public void onClick(ClickEvent event) {
		presenter.sendButtonClicked();
	}
	
}
